<template>
<view class="page_gap page_news">
  <text class="h1" id="newsTitle">{{newsData.sTitle}}</text>
  <view class="news_info">
    <text class="span" id="newsAuthor">{{newsData.sFrom}}</text>
    <text class="span" id="newsDate">{{newsData.time}}</text>
  </view>
  <view id="font-adjust">
    <view id="newsRelative" class="news_relative"></view>
    <view id="summary" class="summary_block">{{newsData.sDescription}}</view>

    <view class="news_txt" id="newsContent">
      <!--<import src="/we7/pages/templates/news.wxml"></import>-->
      <block data-type="template" data-is="newsDetail" data-attr="...newsData">
  <block v-for="(cellData, idy) in content" :key="idy">
    <block v-if="cellData.type == 'view'">
      <view class="p">
        <block v-for="(item, index) in cellData.child" :key="index">
          <block v-if="item.type == 'a'">
            <text class="a" :data-seccode="item.attr['data-seccode']" :data-secname="item.attr['data-secname']" @tap="stockClick">{{item.text}}</text>
          </block>
          <block v-else>
            <text>{{item.text}}</text>
          </block>
        </block>
      </view>
    </block>
    <block v-if="cellData.type == 'img'">
      {{wn_html_images}}
      <image class="img" :data-index="idy" mode="widthFix" :src="cellData.attr.src" @load="imageLoad" :style="'width: ' + cellData['attr']['width'] + 'max-width: 100%height: ' + (cellData['attr']['height'] ? cellData['attr']['height'] : auto)"></image>
    </block>
  </block>
</block>
    </view>
  </view>
</view>
</template>

<script>
var appInstance = getApp(); //获取全局变量
//获取全局变量
var R_htmlToWxml = require("../../resource/js/htmlToWxml.js"); //引入公共方法

export default {
  data() {
    return {
      scrollHeight: 0,
      newsData: {}
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    this.getNewsDetail(); // 开始加载页面

    console.log("onLoad");
  },
  onShow: function () {
    // 页面显示
    console.log("onShow");
  },
  onReady: function () {
    // 页面渲染完成
    console.log("onReady");
  },
  onHide: function () {
    // 页面隐藏
    console.log("onHide");
  },
  onUnload: function () {
    // 页面关闭
    console.log("onUnload");
  },
  methods: {
    getNewsDetail: function () {
      var that = this;
      wx.request({
        url: 'https://wedengta.com/wxnews/getNews?action=DiscNewsContent&type=4&id=1478677877_1406730_1_9',
        headers: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          var data = res.data;

          if (data.ret == 0) {
            var newsDetail = JSON.parse(data.content);
            newsDetail.content = R_htmlToWxml.html2json(newsDetail.sContent);
            newsDetail.time = appInstance.globalData.util.formatTime(newsDetail.iTime * 1000);
            that.setData({
              newsData: newsDetail
            });
          } else {
            console.log("数据拉取失败");
          }
        },
        fail: function (error) {
          console.log("数据拉取失败");
        }
      });
    },
    stockClick: function (e) {
      var secCode = e.currentTarget.dataset.seccode;
      var secName = e.currentTarget.dataset.secname;
      console.log("stockClick:" + secCode + ";secName:" + secName);
    }
  }
};
</script>
<style>
@import "./newsDetail.css";
</style>